package com.coocaa.ops.admin.v1.module.convert;

import com.coocaa.ops.common.core.biz.module.entity.ModuleInfoEntity;
import com.coocaa.ops.common.core.biz.module.entity.ModuleTabContentConfigInfo;
import com.coocaa.ops.common.tool.base.InstanceUtil;
import lombok.experimental.UtilityClass;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author bijiahao
 * @description
 * @date 2020/6/14 17:18
 */
@UtilityClass
public class ModuleQueryConverter {

    public static void handleSetDmpTab(ModuleInfoEntity entity, List<ModuleTabContentConfigInfo> dmpTabList){
        if(CollectionUtils.isEmpty(dmpTabList)){
            return;
        }
        entity.setTopTabDmpList(filterDmpTabListBySeq(1, dmpTabList));
        entity.setBottomTabDmpList(filterDmpTabListBySeq(2, dmpTabList));
    }

    private static  List<ModuleTabContentConfigInfo> filterDmpTabListBySeq(Integer seq, List<ModuleTabContentConfigInfo> dmpTabList){
        List<ModuleTabContentConfigInfo> result = InstanceUtil.newArrayList();
        for(ModuleTabContentConfigInfo moduleTabContentConfigInfo : dmpTabList){
            if (Objects.equals(seq, moduleTabContentConfigInfo.getTabSeq())){
                result.add(moduleTabContentConfigInfo);
            }

        }
        return result;
    }


    public static void handleOnclick(ModuleInfoEntity module) {
        //默认点击事件不返还给前端
        if (Objects.equals(module.getOnclickDefault(), 1)) {
            module.setOnclick(null);
        }
    }
}
